import {
	defineStore
} from 'pinia'
import {
	ref,
	computed
} from 'vue'

export default defineStore('userInfo', () => {
	// const userInfo = ref(uni.getStorageSync('userInfo') || {})
	const userInfo = computed(() => {
		return uni.getStorageSync('userInfo') || {}
	})

	// 设置 Token
	const setUserInfo = (newVal) => {
		userInfo.value = newVal
		uni.setStorageSync('userInfo', newVal)
	}

	// 清除 Token
	const clearUserInfo = () => {
		userInfo.value = {}
		uni.removeStorageSync('userInfo')
	}

	return {
		userInfo,
		setUserInfo,
		clearUserInfo
	}
}, {
	persist: true
})